﻿

//保存需要索引的标签
//function SaveColumns() {
//    var page = $(window.frames["xhe0_iframe"].document);
//    var e = $(page).find('div[colname]');   //colname属性不为空
//    var id, column,key, content;
//    var count = 0;
//    
//    for (var i = 0; i < e.length; i++) {

//        id = $(e[i]).attr("id");
//        column = $(e[i]).attr("colname");
//        key = $(e[i]).find('h2[ptype="colinfo_key"]').html(); ;
//        content = $(e[i]).html();
//        $.ajax({
//            type: "POST",
//            url: "eGold.ashx",
//            dataType: "html",
//            data: { action: "SaveColumns", key: escape(key), content: escape(content), column: column },
//            success: function (result) {
//               // alert('保存成功!');
//            }
//        });
//    }

//}

//把excel转换为table标签
function GetTableFromExcel(a) {
    var thead, tbody;
    var rows = a.split('\n');
    var strTable = "";
    strTable = "<div class=\"mc_tab\"><table width=\"90%\" border=\"0\" cellpadding=\"0\" cellspacing=\"1\" class=\"mtab\">";
    thead = "";
    tbody = "";
    for (var i = 0; i < rows.length; i++) {
        strTable += "<tr>";
        var cols = rows[i].split('\t');

        //表头和首列颜色深<th>
        if (i == 0) {
            for (var j = 0; j < cols.length; j++) {
                strTable += "<th>";
                strTable += cols[j];
                strTable += "</th>";
            }
        }
        else {
            for (var j = 0; j < cols.length; j++) {
                if (j == 0) {
                    if (cols[j] != '') {
                        strTable += "<th>";
                        strTable += cols[j];
                        strTable += "</th>";
                    }
                }
                else {
                    strTable += "<td >";
                    strTable += cols[j];
                    strTable += "</td>";
                }
            }
        }

      
        strTable += "</tr>";
    }
    strTable += "</div></table>";
    return strTable;
}


//大势图解的excel
function GetTableFromExcelDstj(a) {
    var thead, tbody;
    var rows = a.split('\n');
    var strTable = "";
    strTable = "<div class=\"mc_tab\"><table width=\"90%\" border=\"0\" cellpadding=\"0\" cellspacing=\"1\" class=\"mtab\">";
    thead = "";
    tbody = "";
    for (var i = 0; i < rows.length; i++) {
        strTable += "<tr>";
        var cols = rows[i].split('\t');

        //表头和首列颜色深<th>
        if (i == 0) {
            for (var j = 0; j < cols.length; j++) {
                if (j == 0) {
                    strTable += "<th width='15%'>";
                }
                else if (j == 1) {
                    strTable += "<th width='20%'>";
                }
                else if (j == 2) {
                    strTable += "<th width='65%'>";
                }
                strTable += cols[j];
                strTable += "</th>";
            }
        }
        else {
            for (var j = 0; j < cols.length; j++) {
                if (j == 0) {
                    if (cols[j] != '') {
                        strTable += "<th  " + GetRowSpan(rows, i) + " >";
                        strTable += cols[j];
                        strTable += "</th>";
                    }
                }
                else if (j == 2) {
                    strTable += "<td style='text-align:left;'>";
                    strTable += cols[j];
                    strTable += "</td>";
                }
                else {
                    strTable += "<td >";
                    strTable += cols[j];
                    strTable += "</td>";
                }
            }
        }


        strTable += "</tr>";
    }
    strTable += "</div></table>";
    return strTable;
}

//判断是否需要rowspan
//rows; 数据 i:当前行,j 当前列
function GetRowSpan(rows, ii) {
    var num = 1;

    for (var i = ii+1; i < rows.length; i++) {
        var cols = rows[i].split('\t');
        if (cols[0] == '') {
            num++;
        }
        else
        {
            break;
        }
    
    }
    return "rowspan='"+num+"'";
}

//把excel转换为table标签
function GetTableFromExcelOfLR(a) {
    var thead, tbody;
    var rows = a.split('\n');
    var strTable = "";
    strTable += "<div class=\"img_0 img_1\" style=\"width:480px;\">";
    strTable += "<div class=\"mc_tab\"><table width=\"90%\" border=\"0\" cellpadding=\"0\" cellspacing=\"1\" class=\"mtab\">";
    thead = "";
    tbody = "";
    for (var i = 0; i < rows.length; i++) {
        strTable += "<tr>";
        var cols = rows[i].split('\t');
        //表头和首列颜色深<th>
        if (i == 0) {
            for (var j = 0; j < cols.length; j++) {
                strTable += "<th>";
                strTable += cols[j];
                strTable += "</th>";
            }
        }
        else {
            for (var j = 0; j < cols.length; j++) {
                if (j == 0) {
                    strTable += "<th>";
                    strTable += cols[j];
                    strTable += "</th>";
                }
                else {
                    strTable += "<td>";
                    strTable += cols[j];
                    strTable += "</td>";
                }
            }
        }
        strTable += "</tr>";
    }
    strTable += "</div></table>";
    strTable += "</div>";
    //strTable += "<p>请在此处填写正文</p>";
    strTable += "<div class=\"clr\"></div>";
    return strTable;
}


//get click position
function Show() {
    var lx = event.x
    var ly = event.y
    alert(lx + "/" + ly);
}

//add artical
function AddArtical() {
    var strHtml = "";
    strHtml += "<div class=\"mc_cnt\">";
    strHtml += "<div class=\"mc_txt\">";
    strHtml += "请在此处填写正文";
    strHtml += "</div></div>";
    $(window.frames["xhe0_iframe"].document).find('body').append(strHtml);
}

//判断是否已发布
function IsPublic(page) {
    $.get("eGold.ashx", { action: "IsPublic", key: $('#pagename').val() },
                   function (data) {
                       if (data == "1") {
                           $('#txt_ispublic').html("此页面今天已发布");
                           $('#ispublic').val("1");
                       }
                       else {
                           $('#txt_ispublic').html("此页面今天还未发布");
                           $('#ispublic').val("0");
                       }
                   });
               }
//发布页面
function SetPublic(page) {

    $.get("eGold.ashx", { action: "AddPublic", key: $('#pagename').val(), date: $('#select_date').val(), type: $('#page_type').val() },
          function (data) {
              alert(data);
              return false;
          });
  }

function GetTitleDate(strDate) {

    var year = strDate.substring(0, 4);
    var month = strDate.substring(5, 7);
    var day = strDate.substring(8.10);

    return year + String(month) + String(day);

}


